package cn.iocoder.yudao.module.famous.doctor.dal.mysql.forum;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.forum.FamForumDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.famous.doctor.controller.admin.forum.vo.*;

/**
 * 论坛表 Mapper
 *
 * @author Test1
 */
@Mapper
public interface FamForumMapper extends BaseMapperX<FamForumDO> {

    default PageResult<FamForumDO> selectPage(FamForumPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<FamForumDO>()
                .likeIfPresent(FamForumDO::getTitle, reqVO.getTitle())
                .likeIfPresent(FamForumDO::getTopicIds, reqVO.getTopicIds())
                .betweenIfPresent(FamForumDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(FamForumDO::getReplyCount, reqVO.getReplyCount())
                .eqIfPresent(FamForumDO::getSpeakType, reqVO.getSpeakType())
                .eqIfPresent(FamForumDO::getIllnessIds, reqVO.getIllnessIds())
                .eqIfPresent(FamForumDO::getIsTop, reqVO.getIsTop())
                .eqIfPresent(FamForumDO::getAudit, reqVO.getAudit())
                .orderByDesc(FamForumDO::getId));
    }

    default List<FamForumDO> selectList(FamForumExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<FamForumDO>()
                .likeIfPresent(FamForumDO::getTitle, reqVO.getTitle())
                .likeIfPresent(FamForumDO::getTopicIds, reqVO.getTopicIds())
                .betweenIfPresent(FamForumDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(FamForumDO::getReplyCount, reqVO.getReplyCount())
                .eqIfPresent(FamForumDO::getSpeakType, reqVO.getSpeakType())
                .eqIfPresent(FamForumDO::getIllnessIds, reqVO.getIllnessIds())
                .eqIfPresent(FamForumDO::getIsTop, reqVO.getIsTop())
                .eqIfPresent(FamForumDO::getAudit, reqVO.getAudit())
                .orderByDesc(FamForumDO::getId));
    }

    default PageResult<FamForumDO> selectPageParticulars(FamForumPageReqVO reqVO) {
        PageResult<FamForumDO> famForumDOPageResult = selectPage(reqVO, new LambdaQueryWrapperX<FamForumDO>()
                .eqIfPresent(FamForumDO::getSpeakType, reqVO.getSpeakType())
                .eqIfPresent(FamForumDO::getTitle, reqVO.getTitle())
                .eqIfPresent(FamForumDO::getTopicIds, reqVO.getTopicIds())
                .eqIfPresent(FamForumDO::getContent, reqVO.getContent())
                .eqIfPresent(FamForumDO::getImageUrl, reqVO.getImageUrl())
                .eqIfPresent(FamForumDO::getVisitCount, reqVO.getVisitCount())
                .eqIfPresent(FamForumDO::getCollectCount, reqVO.getCollectCount())
                .eqIfPresent(FamForumDO::getIsTop, reqVO.getIsTop())
                .betweenIfPresent(FamForumDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(FamForumDO::getReplyCount, reqVO.getReplyCount())
                .eqIfPresent(FamForumDO::getAudit, reqVO.getAudit())
                .last("ORDER BY CASE WHEN is_top = 1 THEN 0 ELSE 1 END, create_time DESC"));
        return famForumDOPageResult;
    }


    default List<FamForumDO> selectList(FamForumPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<FamForumDO>()
                .likeIfPresent(FamForumDO::getTitle, reqVO.getTitle())
                .likeIfPresent(FamForumDO::getTopicIds, reqVO.getTopicIds())
                .betweenIfPresent(FamForumDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(FamForumDO::getReplyCount, reqVO.getReplyCount())
                .eqIfPresent(FamForumDO::getSpeakType, reqVO.getSpeakType())
                .eqIfPresent(FamForumDO::getIllnessIds, reqVO.getIllnessIds())
                .eqIfPresent(FamForumDO::getIsTop, reqVO.getIsTop())
                .eqIfPresent(FamForumDO::getAudit, reqVO.getAudit())
                .last("order by rand() LIMIT "+reqVO.getPageSize()));
    }
}
